package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduAssignmentSubmissionDTO;
import com.zenith.edu.po.vo.EduAssignmentSubmissionVO;
import com.zenith.edu.service.EduAssignmentSubmissionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/assignment-submission")
@Tag(name = "作业提交管理", description = "作业提交管理接口")
public class EduAssignmentSubmissionController {
    
    @Autowired
    private EduAssignmentSubmissionService eduAssignmentSubmissionService;
    
    @SecurePostMapping(value = "createAssignmentSubmission",roles = {"ADMIN"},permission = "assignment:create")
    @Operation(summary = "创建作业提交")
    public Result<EduAssignmentSubmissionVO> createAssignmentSubmission(@RequestBody EduAssignmentSubmissionDTO dto) {
        EduAssignmentSubmissionVO assignmentSubmissionVO = eduAssignmentSubmissionService.createAssignmentSubmission(dto);
        return Result.success(assignmentSubmissionVO);
    }
    
    @SecurePostMapping(value = "/getAssignmentSubmissionById/{id}",roles = "ROLE_TEACHER",permission = "EDU_ASSIGNMENT_SUBMISSION_GET_BY_ID")
    @Operation(summary = "根据ID获取作业提交详情")
    public Result<EduAssignmentSubmissionVO> getAssignmentSubmissionById(@PathVariable Long id) {
        EduAssignmentSubmissionVO assignmentSubmissionVO = eduAssignmentSubmissionService.getAssignmentSubmissionById(id);
        if (assignmentSubmissionVO == null) {
            return Result.fail("作业提交不存在");
        }
        return Result.success(assignmentSubmissionVO);
    }
    
    @SecurePostMapping(value = "updateAssignmentSubmission",roles = {"ADMIN"},permission = "assignment:update")
    @Operation(summary = "更新作业提交信息")
    public Result<EduAssignmentSubmissionVO> updateAssignmentSubmission(@RequestBody EduAssignmentSubmissionDTO dto) {
        EduAssignmentSubmissionVO assignmentSubmissionVO = eduAssignmentSubmissionService.updateAssignmentSubmission(dto);
        return Result.success(assignmentSubmissionVO);
    }
    
    @SecurePostMapping(value = "deleteAssignmentSubmission",roles = {"ADMIN"},permission = "assignment:delete")
    @Operation(summary = "删除指定作业提交")
    public Result<Void> deleteAssignmentSubmission(@PathVariable Long id) {
        boolean result = eduAssignmentSubmissionService.deleteAssignmentSubmission(id);
        if (!result) {
            return Result.fail("作业提交删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getAssignmentSubmissionList",roles = {"ADMIN"},permission = "assignment:list")
    @Operation(summary = "获取作业提交列表")
    public Result<List<EduAssignmentSubmissionVO>> getAssignmentSubmissionList() {
        List<EduAssignmentSubmissionVO> assignmentSubmissionList = eduAssignmentSubmissionService.getAssignmentSubmissionList();
        return Result.success(assignmentSubmissionList);
    }
}